<?php
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $fecha1 = $_REQUEST['capass2'];
    $fecha2 = $_REQUEST['capass22'];
    
    $f1 = date('Y-m-d',strtotime($fecha1));
    $f2 = date('Y-m-d',strtotime($fecha2));
    
    $indi = "select case when ate_conducta = 'hg' then 'Pacientes Hospitalizadas en Gineco-Obstetricia' end as res,hg.total 
            from atenMaterna as atm
                    outer apply(select COUNT(DISTINCT adnIngreso)as total
                                            from atenMaterna 
                                            where ate_fecha between '".$f1."' and '".$f2."' and ate_conducta = 'hg')as hg
            where atm.ate_conducta = 'hg'
            group by ate_conducta,hg.total
            union
            select case when ate_conducta = 'di' then 'Pacientes Devueltas con Indicaciones' end as res,hg.total 
            from atenMaterna as atm
                    outer apply(select COUNT(DISTINCT adnIngreso)as total
                                            from atenMaterna 
                                            where ate_fecha between '".$f1."' and '".$f2."' and ate_conducta = 'di')as hg
            where atm.ate_conducta = 'di'
            group by ate_conducta,hg.total
            union
            select case when ate_conducta = 'ho' then 'Pacientes Hospitalizadas en Otro Servicio' end as res,hg.total 
            from atenMaterna as atm
                    outer apply(select COUNT(DISTINCT adnIngreso)as total
                                            from atenMaterna 
                                            where ate_fecha between '".$f1."' and '".$f2."' and ate_conducta = 'ho')as hg
            where atm.ate_conducta = 'ho'
            group by ate_conducta,hg.total
            union
            select case when ate_conducta = 'do' then 'Pacientes en Observacion' end as res,hg.total 
            from atenMaterna as atm
                    outer apply(select COUNT(DISTINCT adnIngreso)as total
                                            from atenMaterna 
                                            where ate_fecha between '".$f1."' and '".$f2."' and ate_conducta = 'do')as hg
            where atm.ate_conducta = 'do'
            group by ate_conducta,hg.total";
    $lsti = $con->query($indi);
    while($res = mssql_fetch_array($lsti)){
        $lst[] = $res;
    }
    $con->cerrarConexion();
    print_r(json_encode($lst));

?>
